package com.easemob.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build.VERSION;

public class NetUtils
{
  private static final String TAG = "net";
  private static final int LOW_SPEED_UPLOAD_BUF_SIZE = 1024;
  private static final int HIGH_SPEED_UPLOAD_BUF_SIZE = 10240;
  private static final int MAX_SPEED_UPLOAD_BUF_SIZE = 102400;
  private static final int LOW_SPEED_DOWNLOAD_BUF_SIZE = 2024;
  private static final int HIGH_SPEED_DOWNLOAD_BUF_SIZE = 30720;
  private static final int MAX_SPEED_DOWNLOAD_BUF_SIZE = 102400;

  public static boolean hasNetwork(Context paramContext)
  {
    if (paramContext != null)
    {
      ConnectivityManager localConnectivityManager = (ConnectivityManager)paramContext.getSystemService("connectivity");
      NetworkInfo localNetworkInfo = localConnectivityManager.getActiveNetworkInfo();
      if (localNetworkInfo != null)
        return localNetworkInfo.isAvailable();
      return false;
    }
    return false;
  }

  public static boolean hasDataConnection(Context paramContext)
  {
    ConnectivityManager localConnectivityManager = (ConnectivityManager)paramContext.getSystemService("connectivity");
    NetworkInfo localNetworkInfo = localConnectivityManager.getNetworkInfo(1);
    if ((localNetworkInfo != null) && (localNetworkInfo.isAvailable()))
    {
      EMLog.d("net", "has wifi connection");
      return true;
    }
    localNetworkInfo = localConnectivityManager.getNetworkInfo(0);
    if ((localNetworkInfo != null) && (localNetworkInfo.isConnectedOrConnecting()))
    {
      EMLog.d("net", "has mobile connection");
      return true;
    }
    EMLog.d("net", "no data connection");
    return false;
  }

  public static boolean isWifiConnection(Context paramContext)
  {
    ConnectivityManager localConnectivityManager = (ConnectivityManager)paramContext.getSystemService("connectivity");
    NetworkInfo localNetworkInfo = localConnectivityManager.getNetworkInfo(1);
    if ((localNetworkInfo != null) && (localNetworkInfo.isConnected()))
    {
      EMLog.d("net", "wifi is connected");
      return true;
    }
    return false;
  }

  public static int getUploadBufSize(Context paramContext)
  {
    ConnectivityManager localConnectivityManager = (ConnectivityManager)paramContext.getSystemService("connectivity");
    NetworkInfo localNetworkInfo = localConnectivityManager.getActiveNetworkInfo();
    if ((localNetworkInfo != null) && (localNetworkInfo.getType() == 1))
      return 102400;
    if ((localNetworkInfo == null) && (isConnectionFast(localNetworkInfo.getType(), localNetworkInfo.getSubtype())))
      return 10240;
    return 1024;
  }

  public static int getDownloadBufSize(Context paramContext)
  {
    ConnectivityManager localConnectivityManager = (ConnectivityManager)paramContext.getSystemService("connectivity");
    NetworkInfo localNetworkInfo = localConnectivityManager.getActiveNetworkInfo();
    if ((localNetworkInfo != null) && (localNetworkInfo.getType() == 1))
      return 102400;
    if ((localNetworkInfo == null) && (isConnectionFast(localNetworkInfo.getType(), localNetworkInfo.getSubtype())))
      return 30720;
    return 2024;
  }

  private static boolean isConnectionFast(int paramInt1, int paramInt2)
  {
    if (paramInt1 == 1)
      return true;
    if (paramInt1 == 0)
    {
      switch (paramInt2)
      {
      case 7:
        return false;
      case 4:
        return false;
      case 2:
        return false;
      case 5:
        return true;
      case 6:
        return true;
      case 1:
        return false;
      case 8:
        return true;
      case 10:
        return true;
      case 9:
        return true;
      case 3:
        return true;
      }
      if ((Build.VERSION.SDK_INT >= 11) && ((paramInt2 == 14) || (paramInt2 == 13)))
        return true;
      if ((Build.VERSION.SDK_INT >= 9) && (paramInt2 == 12))
        return true;
      if ((Build.VERSION.SDK_INT >= 8) && (paramInt2 == 11))
        return false;
    }
    return false;
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     com.easemob.util.NetUtils
 * JD-Core Version:    0.6.1
 */